// pages/life/life.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        musics:[]
    },
    onLoad: function (options) {
        // console.log("onload")
        var url = 'http://47.108.197.28:3000/top/playlist?order=hot'
        wx.request({
            url,
            method: 'GET',
            success: (res)=>{
                var musics = [];
                var playlists = res.data.playlists;
                playlists.forEach(item=>{
                    var {id,name,coverImgUrl} = item;
                    musics.push({
                        id,
                        name,
                        coverImgUrl
                    })
                })
                // console.log(musics)

                this.setData({
                    musics
                })
            }
        });
    },
    handleDelete(event){
        var {aid} = event.currentTarget.dataset
        var musics = this.data.musics;
        var index = musics.findIndex(item=>{
            return item.id == aid;
        })
        musics.splice(index,1);
        this.setData({
            musics
        })
    }

    
})